package com.zhongan.consul.demo;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.ecwid.consul.json.GsonFactory;
import com.ecwid.consul.transport.RawResponse;
import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.ConsulRawClient;
import com.ecwid.consul.v1.agent.model.Service;
import com.ecwid.consul.v1.health.model.HealthService;
import com.google.common.reflect.TypeToken;

public class ConsulClient3 {

	public static void main(String[] args) {
		ConsulRawClient client = new ConsulRawClient("10.253.100.84", 8500);
		RawResponse rawResponse = client.makeGetRequest("/v1/health/service/com.zhongan.life.sales.config.service.ActivityInfoService2", null);
		if (rawResponse.getStatusCode() == 200) {
			List<HealthService> healthServices = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<HealthService>>() {
			}.getType());
			for (HealthService healthService : healthServices) {
				System.out.println(healthService.getService().getAddress() + ":" + healthService.getService().getPort() + "," + healthService.getService().getService() + "," + healthService.getService().getTags());
			}
		}

	}

}
